package com.ry.util.timepick;

import java.util.Calendar;


import com.ry.util.timepick.labeler.TimeLabeler;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class DateTimeDialogActivity extends Activity {
	
	static final int DATETIMESELECTOR_ID = 1;
	private TextView dateText;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.timemain);
        
        dateText = (TextView) this.findViewById(R.id.selectedDateLabel);
        ((Button) findViewById(R.id.showTime)).setOnClickListener(new View.OnClickListener() {
			
			public void onClick(View v) {
				showDialog(DATETIMESELECTOR_ID);
			}
		});
    }
    
    private DateSlider.OnDateSetListener mDateTimeSetListener =
        new DateSlider.OnDateSetListener() {
            public void onDateSet(DateSlider view, Calendar selectedDate) {
                // update the dateText view with the corresponding date
                int minute = selectedDate.get(Calendar.MINUTE) /
                        TimeLabeler.MINUTEINTERVAL*TimeLabeler.MINUTEINTERVAL;
                dateText.setText(String.format("选中的日期是:%n%tY年%tm月%te日 %tH:%02d",
                        selectedDate, selectedDate, selectedDate, selectedDate, minute));
            }
    };
    
    @Override
    protected Dialog onCreateDialog(int id) {
    	final Calendar c = Calendar.getInstance();
    	return new DateTimeSlider(this,mDateTimeSetListener,c);
    }
}